from django_filters import rest_framework
from .models import Project, ProjectAppeal


class ProjectFilter(rest_framework.FilterSet):
    name = rest_framework.CharFilter(lookup_expr='contains')
    desc = rest_framework.CharFilter(lookup_expr='contains')
    leader = rest_framework.CharFilter(lookup_expr='contains')

    class Meta:
        model = Project
        fields = ['name', 'desc', 'leader', 'user']


class ProjectAppealFilter(rest_framework.FilterSet):
    project_name = rest_framework.CharFilter(lookup_expr='contains', field_name='project__name')
    project_create_by_id = rest_framework.CharFilter(field_name='project__create_by_id')
    project_create_by = rest_framework.CharFilter(field_name='project__create_by__username', lookup_expr='contains')
    user_name = rest_framework.CharFilter(lookup_expr='contains', field_name='user__username')

    class Meta:
        model = ProjectAppeal
        fields = ['project_name', 'user_name', 'project_create_by_id', 'user', 'project_create_by']